//
//  FiveViewController.m
//  DemoTest
//
//  Created by DaShuEdu on 2017/4/25.
//  Copyright © 2017年 DaShuEdu. All rights reserved.
//

#import "FiveViewController.h"
#import "DSPageView.h"
#import "DSPageStyle.h"

@interface FiveViewController ()

@end

@implementation FiveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor purpleColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    DSPageStyle *pageStyle = [[DSPageStyle alloc] init];
    pageStyle.isScrollEnable = YES;
    pageStyle.isShowBottomLine = YES;
    pageStyle.isScaleEnable = NO;
    pageStyle.isShowCoverView = NO;
    pageStyle.selectColor = [UIColor blackColor];
    pageStyle.normalColor = [UIColor darkGrayColor];
    pageStyle.bottomLineHeight = 2;
    pageStyle.titleSize = 14;
    pageStyle.titleMargin = 64;
    pageStyle.titleHeight = 34;
    
    NSArray *titles = @[@"昨天阴",@"今天晴",@"明天圆",@"明天的明天",@"未来缺"];
    // 获取控制器
    NSMutableArray *childVcs = [NSMutableArray arrayWithCapacity:5];
    for (int i = 0; i<titles.count; i++) {
        UIViewController *vc = [[UIViewController alloc] init];
        UIColor *color;
        switch (i) {
            case 0:
                color = [UIColor whiteColor];
                break;
            case 1:
                color = [UIColor yellowColor];
                break;
            case 2:
                color = [UIColor greenColor];
                break;
            case 3:
                color = [UIColor blueColor];
                break;
            case 4:
                color = [UIColor redColor];
                break;
            default:
                color = [UIColor grayColor];
                break;
        }
        vc.view.backgroundColor = color;
        [childVcs addObject:vc];
    }
    // 创建DSPageView
    CGRect pageFrame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64);
    DSPageView *pageView = [[DSPageView alloc] initWithFrame:pageFrame sytle:pageStyle titles:titles childVcs:childVcs parentVc:self];
    pageView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:pageView];
    
    [self notify];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)notify
{
    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
    dispatch_queue_t queue1 = dispatch_queue_create("testGroup", DISPATCH_QUEUE_SERIAL);
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_notify(group, dispatch_get_main_queue(), ^(){
        NSLog(@"end");
    });
    dispatch_group_async(group, queue, ^(){
        NSLog(@"dispatch-1");
    });
    dispatch_group_async(group, queue, ^(){
        NSLog(@"dispatch-2");
    });
    dispatch_group_async(group, queue, ^(){
        NSLog(@"dispatch-3");
    });
    dispatch_group_async(group, queue, ^(){
        NSLog(@"dispatch-4");
    });
    dispatch_group_async(group, queue, ^(){
        NSLog(@"dispatch-5");
    });
    
    
    
}

- (void)wait
{
    dispatch_queue_t aDQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();
    // Add a task to the group
    dispatch_group_async(group, aDQueue, ^{
        printf("task 1 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 2 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 3 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 4 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 5 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 6 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 7 \n");
    });
    printf("wait 1 2 3 \n");
    dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
    printf("task 1 2 3 finished \n");
    
    group = dispatch_group_create();
    // Add a task to the group
    dispatch_group_async(group, aDQueue, ^{
        printf("task 4 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 5 \n");
    });
    dispatch_group_async(group, aDQueue, ^{
        printf("task 6 \n");
    });
    printf("wait 4 5 6 \n");
    dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
    printf("task 4 5 6 finished \n");
    
}

- (void)enter
{
    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^(){
        NSLog(@"end");
    });
    
    dispatch_group_enter(group);
    
    dispatch_async(queue, ^(){
        NSLog(@"dispatch-1");
        
        dispatch_group_leave(group);
    });
    
    dispatch_async(queue, ^(){
        NSLog(@"dispatch-2");
    });
    
    dispatch_async(queue, ^(){
        NSLog(@"dispatch-3");
    });
    
    dispatch_async(queue, ^(){
        NSLog(@"dispatch-4");
    });
    
    dispatch_async(queue, ^(){
        NSLog(@"dispatch-5");
    });
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
